import { useSelector, useDispatch } from "react-redux";

const useStore = () => {
  const userData = useSelector((state) => state.userData);
  const loading = useSelector((state) => state.loading);
  const collapsed = useSelector((state) => state.collapsed);
  const currentPath = useSelector((state) => state.currentPath);


  const dispatch = useDispatch();
  const login = (data) => {
    dispatch({
      type: "LOGIN",
      payload: data,
    });
  };
  const logout = () => {
    dispatch({
      type: "LOGOUT",
    });
  };

  const toggle = () => {
    dispatch({
      type: "TOGGLE",
    });
  };
  const showLoading = () => {
    dispatch({
      type: "SHOWLOADDING",
    });
  };

  const hideLoading = () => {
    dispatch({
      type: "HIDELOADDING",
    });
  };
  const setCurrentPath = (data) => {
    dispatch({
      type: "SETCURRENTPATH",
      payload: data,
    });
  };
  const setFirstLoginChecked = () => {
    dispatch({
      type: "FIRSTLOGINCHECKED",
    });
  };

  return {
    userData,
    currentPath,
    loading,
    collapsed,
    login,
    logout,
    toggle,
    showLoading,
    hideLoading,
    setCurrentPath,
  };
};

export default useStore;
